package tests;

import java.sql.ResultSet;
import java.util.ArrayList;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.davinci.freemarket.dataAccessLayer.accessdata.categorias.CategoriasDAO;
import com.davinci.freemarket.dataModelLayer.model.DBAttibuteModel;
import com.microsoft.sqlserver.jdbc.SQLServerException;


/**
 * @author Nicolas Reymundo
 *
 */


public class CategoriaUnitTesting {

	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
	}
	
	
	@Test
	public void selectCategoria(){
		CategoriasDAO categoriasdao = new CategoriasDAO();
		
		ArrayList<DBAttibuteModel> conditions = new ArrayList<DBAttibuteModel>();
		conditions.add(new DBAttibuteModel("CATEGORIA", "%Test%"));
		
		ResultSet rs = categoriasdao.selectCategorias(conditions);
		Assert.assertTrue(rs != null);
		String result = "";
		try {
			while (rs.next()) {
				result += rs.getString(1) + ", " + rs.getString(2);
			}
			System.out.println(result);
		}
		catch (SQLServerException e) {
			System.out.println(e);
		}
		catch (Exception e) {
			System.out.println(e);
		}
	}
	
	
	
	@Test
	/*
	 * No tengo *NI* idea si el parametro "Date.valueOf(STRING)" se lleva bien con SQL, probablemente no. 
	 */
	public void addCategoria(){
		CategoriasDAO categoriasdao = new CategoriasDAO();
		int rs = categoriasdao.addCategoria("categoriaTest");
		Assert.assertTrue(rs != 0);
	}
	
	@Test
	/*
	 * No tengo *NI* idea si el parametro "Date.valueOf(STRING)" se lleva bien con SQL, probablemente no. 
	 */
	public void modifyPublicacion(){
		CategoriasDAO categoriasdao = new CategoriasDAO();
		int rs = categoriasdao.modifyCategoria(11, "categoriaTestUpdt");
		Assert.assertTrue(rs != 0);
	}
	
	@Test
	public void deletePublicacion(){
		CategoriasDAO categoriasdao = new CategoriasDAO();
		int rs = categoriasdao.deleteCategoria(11);
		Assert.assertTrue(rs != 0);
	}
	
	
}
